package com.tarena.dubbo.client.proxy;

import com.tarena.dubbo.server.StockApi;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class ProxyStockApi implements StockApi {
    @Override
    public void reduceStock(String num) throws IOException {
        //TODO 先从 nacos拿到一批server注册信息 所有实例 ip：port
        //从这个列表中选择一个ip:port
        //建立一个socket连接,将数据序列化 做outPut输出 让server端执行reduceStock
        Socket socket=new Socket("127.0.0.1",20000);
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dos=new DataOutputStream(outputStream);
        dos.writeUTF(num);
        dos.flush();
    }

    @Override
    public void returnStock(String num) throws IOException {
        //建立一个socket连接,将数据序列化 做outPut输出 让server端执行reduceStock
        Socket socket=new Socket("127.0.0.1",20000);
        OutputStream outputStream = socket.getOutputStream();
        DataOutputStream dos=new DataOutputStream(outputStream);
        dos.writeUTF(num);
        dos.flush();
    }
}
